package jvm;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ClassInitTest {
    private static final Integer stvalue=1;
    private static int stulong=50;
    static {
        System.out.println("常量"+stvalue);
        System.out.println(stulong);
    }

    public static void s(){
        System.out.println("我是父类s方法");
    }

    {
        System.out.println("我是普通代码快");
    }
    public ClassInitTest(){
        System.out.println("构造方法");
    }

    public static void main(String[] args) {
        try {
            Class<ClassInitTest> classInitTestClass = ClassInitTest.class;
            System.out.println(classInitTestClass);
//            TwoParentTest twoParentTest = new TwoParentTest();
            ClassLoadOverried twoParentTest = new ClassLoadOverried();
            Class<?> aClass = twoParentTest.findClass(
                    "jvm.ClassInitTest");
            Constructor<?> constructor = aClass.getConstructor(null);
            Object o = constructor.newInstance(null);
            System.out.println(o.getClass().getClassLoader());
            System.out.println(o);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
